import { request } from '@/utils/requestWrapper';

import { tokenStore } from "@/store/tokenStore";
import type { API } from './typings';

const tokenStoreInstance = tokenStore();

/** 添加订单 POST /api/order/add */
export async function addOrderUsingPost(
  body: API.OrderAddRequest,
  options?: { [key: string]: any }
) {
  return request<API.BaseResponseLong_>({
    url: "/api/order/add",
    method: "POST",
    header: {
      'Authorization': tokenStoreInstance.getToken,
      'content-type': 'application/json'
    },
    data: body,
    ...options
  });
}

/** 支付订单 POST /api/order/pay */
export async function payOrderUsingPost(
  orderId: number,
  options?: { [key: string]: any }
) {
  return request<API.BaseResponseBoolean_>({
    url: "/api/order/pay",
    method: "POST",
    header: {
      'Authorization': tokenStoreInstance.getToken,
      'content-type': 'application/json'
    },
    data: { id: orderId },
    ...options
  });
}

/** getOrderPrice GET /api/order/price */
export async function getOrderPriceUsingGet(
  // 叠加生成的Param类型 (非body参数swagger默认没有生成对象)
  params: API.getOrderPriceUsingGETParams,
  options?: { [key: string]: any }
) {
  return request<API.BaseResponseOrderPriceVO_>({
    url: "/api/order/price",
    method: "GET",
    header: {
      'Authorization': tokenStoreInstance.getToken,
      'content-type': 'application/json'
    },
    params: {
      ...params,
    },
    ...options
  });
}

/** 确认收货 POST /api/order/confirm-receipt */
export async function confirmReceiptUsingPost(
  orderId: number,
  options?: { [key: string]: any }
) {
  return request<API.BaseResponseBoolean_>({
    url: "/api/order/confirm-receipt",
    method: "POST",
    header: {
      'Authorization': tokenStoreInstance.getToken,
      'content-type': 'application/json'
    },
    data: { id: orderId },
    ...options
  });
}

/** 取消订单 POST /api/order/cancel */
export async function cancelOrderUsingPost(
  orderId: number,
  options?: { [key: string]: any }
) {
  return request<API.BaseResponseBoolean_>({
    url: "/api/order/cancel",
    method: "POST",
    header: {
      'Authorization': tokenStoreInstance.getToken,
      'content-type': 'application/json'
    },
    data: { id: orderId },
    ...options
  });
}

/** 申请退款 POST /api/order/refund */
export async function refundOrderUsingPost(
  orderId: number,
  options?: { [key: string]: any }
) {
  console.log('申请退款，订单ID:', orderId); // 添加调试日志
  return request<API.BaseResponseString_>({
    url: "/api/order/refund",
    method: "POST",
    header: {
      'Authorization': tokenStoreInstance.getToken,
      'content-type': 'application/json'
    },
    data: { id: orderId },
    ...options
  });
}

/** 删除订单 POST /api/order/delete */
export async function deleteOrderUsingPost(
  body: API.DeleteRequest,
  options?: { [key: string]: any }
) {
  return request<API.BaseResponseBoolean_>({
    url: "/api/order/delete",
    method: "POST",
    header: {
      'Authorization': tokenStoreInstance.getToken,
      'content-type': 'application/json'
    },
    data: body,
    ...options
  });
}

/** 编辑订单 POST /api/order/edit */
export async function editOrderUsingPost(
  body: API.OrderEditRequest,
  options?: { [key: string]: any }
) {
  return request<API.BaseResponseBoolean_>({
    url: "/api/order/edit",
    method: "POST",
    header: {
      'Authorization': tokenStoreInstance.getToken,
      'content-type': 'application/json'
    },
    data: body,
    ...options
  });
}

/** 获取订单详情 GET /api/order/get/vo */
export async function getOrderVoByIdUsingGet(
  params: {
    id?: string | number;
  },
  options?: { [key: string]: any }
) {
  return request<API.BaseResponseOrderVO_>({
    url: "/api/order/get/vo",
    method: "GET",
    header: {
      'Authorization': tokenStoreInstance.getToken,
      'content-type': 'application/json'
    },
    params,
    ...options
  });
}

/** 分页获取订单列表 POST /api/order/list/page/vo */
export async function listOrderVoByPageUsingPost(
  body: API.OrderQueryRequest,
  options?: { [key: string]: any }
) {
  return request<API.BaseResponsePageOrderVO_>({
    url: "/api/order/list/page/vo",
    method: "POST",
    header: {
      'Authorization': tokenStoreInstance.getToken,
      'content-type': 'application/json'
    },
    data: body,
    ...options
  });
}

/** 获取我的订单列表 POST /api/order/my/list/page/vo */
export async function listMyOrderVoByPageUsingPost(
  body: API.OrderQueryRequest,
  options?: { [key: string]: any }
) {
  return request<API.BaseResponsePageOrderVO_>({
    url: "/api/order/my/list/page/vo",
    method: "POST",
    header: {
      'Authorization': tokenStoreInstance.getToken,
      'content-type': 'application/json'
    },
    data: body,
    ...options
  });
}

/** 更新订单 POST /api/order/update */
export async function updateOrderUsingPost(
  body: API.OrderUpdateRequest,
  options?: { [key: string]: any }
) {
  return request<API.BaseResponseBoolean_>({
    url: "/api/order/update",
    method: "POST",
    header: {
      'Authorization': tokenStoreInstance.getToken,
      'content-type': 'application/json'
    },
    data: body,
    ...options
  });
}

/** 批量添加订单并支付 POST /api/order/add/batch */
export async function addOrderBatchUsingPost(
  body: API.OrderAddBatchRequest,
  options?: { [key: string]: any }
) {
  return request<API.BaseResponseBoolean_>({
    url: "/api/order/add/batch",
    method: "POST",
    header: {
      "Content-Type": "application/json",
      'Authorization': tokenStoreInstance.getToken,
    },
    data: body,
    ...(options || {}),
  });
}